# -*- coding: utf-8 -*-
"""
 @Time    : 2021/2/5 下午3:38
 @Author  : tgy
 
"""

class Descriptor:

    def __get__(self, instance, owner):
        return instance.age

    def __set__(self, instance, value):
        if not isinstance(value,int):
            raise TypeError('age must int type')
        instance.age = value


class Person:

    age = Descriptor()

    def __init__(self, name):
        self._name = name

    @property
    def name(self):
        return self._name

    # 下面的name其实已经指向了property对象
    @name.setter
    def name(self, name):

        if not isinstance(name,str):
            raise TypeError('name must str type')
        self._name = name


if __name__ == '__main__':
    ...
    person = Person('lisi')
    print(person.name)
    person.name = 12
